package com.study.design.pattern.pattern.creational.singleton.reflectattack;

/**
 * @Author: gongsl
 * @Date: 2025-02-23 15:07
 * @description:
 */
public class InnerclassSingleton {
    private InnerclassSingleton() {
        // 私有构造函数
        if (Holder.INSTANCE != null) {
            throw new RuntimeException("防止反射创建实例");
        }
    }

    private static class Holder {
        private static InnerclassSingleton INSTANCE = new InnerclassSingleton();
    }

    public static InnerclassSingleton getInstance() {
        return InnerclassSingleton.Holder.INSTANCE;
    }
}
